package com.wltjack.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.wltjack.common.Response;
import com.wltjack.dao.model.UserEntity;
import com.wltjack.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/selectAll")
    public Response selectAll() {
        List<UserEntity> userEntities = userService.selectAll(new UserEntity());
        if (userEntities != null) {
            Response response = new Response(0,"成功",userEntities);
            return response;
        }
        return new Response(-1000,"not found data",null);
    }

    @GetMapping(value = "/selectAll2")
    public String selectAll2() {
        List<UserEntity> userEntities = userService.selectAll(new UserEntity());
        if (userEntities != null) {
            Response response = new Response(0,"成功",userEntities);
            return JSONObject.toJSONString(response);
        }
        return JSONObject.toJSONString(new Response(-1000,"not found data",null));
    }

    @GetMapping(value="/getPage")
    public Response getPage(@RequestParam(value="pageNo",defaultValue = "0") int pageNo,
                            @RequestParam(value="pageSize",defaultValue = "10") int pageSize) {
        PageInfo<UserEntity> page = userService.getPage(pageNo, pageSize);
        return new Response(0, "成功",page);
    }
}
